package com.mdr.imedera.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import sun.misc.Request;

/**
 * @PACKAGE_NAME: com.mdr.imedera.util
 * @NAME: wxb
 * @USER: Administrator
 * @DATE: 2020/10/22
 * @TIME: 13:35
 * @YEAR: 2020
 * @MONTH: 10
 * @MONTH_NAME_SHORT: 10月
 * @MONTH_NAME_FULL: 十月
 * @DAY: 22
 * @DAY_NAME_SHORT: 周四
 * @DAY_NAME_FULL: 星期四
 * @HOUR: 13
 * @MINUTE: 35
 * @PROJECT_NAME: imedera
 **/

public class RequestResult<T> {

    private Integer errcode;

    private String errmsg;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public RequestResult() {
    }

    public RequestResult(Integer errcode, String errmsg) {
        this.errcode = errcode;
        this.errmsg = errmsg;
    }

    public static RequestResult failure(Integer errcode,String errmsg){
        RequestResult requestResult = failure(errmsg);
        requestResult.setErrcode(errcode);
        return requestResult;
    }

    public static RequestResult failure(String errmsg){
        RequestResult requestResult = new RequestResult();
        requestResult.setErrcode(1);
        requestResult.setErrmsg(errmsg);
        return requestResult;
    }

    public static RequestResult success(String errmsg){
        RequestResult requestResult = new RequestResult();
        requestResult.setErrcode(0);
        requestResult.setErrmsg(errmsg);
        return requestResult;
    }

    public static RequestResult success(String errmsg,Object object){
        RequestResult requestResult = success(errmsg);
        requestResult.setData(object);
        return requestResult;
    }



    public Integer getErrcode() {
        return errcode;
    }

    public void setErrcode(Integer errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
